import Vue from 'vue';
import VueRouter from 'vue-router';
import store from '../store';
import MainRoute from './mainRoute';
import Notfound from './notFoundRoute';

// 解决Vue-Router升级导致的Uncaught(in promise) navigation guard问题
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};
Vue.use(VueRouter);

const routes = [
  {
    path: '/',
    meta: {},
    name: 'Main',
    redirect: '/home',
    component: () => import(/* webpackChunkName: "home" */ '@/layouts/BaseLayout'),
    children: MainRoute
  },
  {
    path: '/login',
    meta: { name: '登录' },
    name: 'Login',
    component: () => import('../views/Login/Login')
  },
  {
    path: '/403',
    name: 'Forbidden',
    component: () => import('../views/Forbidden/Forbidden')
  },
  ...Notfound
];

const router = new VueRouter({
  mode: 'history',
  // mode: 'hash',
  base: process.env.BASE_URL,
  routes
});

export default router;
